Passed
Push — master ( 6f8171...7c2bcd )
by
unknown
48s
created

JobSeekerAPI.saveJobSeekerProfile   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 1
rs 10
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
7
8
var JobSeekerAPI = {};
9
JobSeekerAPI.jobSeekers = [];
10
JobSeekerAPI.profilePicUploader = null;
11
JobSeekerAPI.defaultFirstName = "Jane";
12
JobSeekerAPI.defaultLastName = "Doe";
13
14
JobSeekerAPI.JobSeekerProfileAnswer = function (question_id, answer) {
15
    this.job_seeker_profile_question_id = question_id;
16
    this.answer = answer;
17
}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
18
19
JobSeekerAPI.JobSeeker = function (
20
        id,
21
        name,
22
        email,
23
        personal_link,
24
        tagline,
25
        twitter_username,
26
        linkedin_username,
27
        answers,
28
        last_updated,
29
        user_id) {
30
    this.id = id;
31
    this.name = name;
32
    this.email = email;
33
    this.personal_link = personal_link;
34
    this.tagline = tagline;
35
    this.twitter_username = twitter_username;
36
    this.linkedin_username = linkedin_username;
37
    this.answers = answers;
38
    this.last_updated = last_updated;
39
    this.user_id = user_id;
40
};
41
42
JobSeekerAPI.localizeJobSeekerProfile = function () {
43
    if (siteContent) {
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable siteContent is declared in the current environment, consider using typeof siteContent === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
44
        document.getElementById("profileEditAnswerCancel").value = siteContent.cancel;
45
        document.getElementById("profileEditAnswerSave").value = siteContent.save;
46
    }
47
}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
48
49
JobSeekerAPI.populateJobSeekerObject = function (jobSeekerJSON) {
50
    var jobSeekerObj = new JobSeekerAPI.JobSeeker();
51
52
    if (jobSeekerJSON) {
53
        jobSeekerObj.id = jobSeekerJSON.job_seeker_profile_id;
54
        jobSeekerObj.name = jobSeekerJSON.job_seeker_profile_name;
55
        jobSeekerObj.email = jobSeekerJSON.job_seeker_profile_email;
56
        jobSeekerObj.personal_link = jobSeekerJSON.job_seeker_profile_link;
57
        jobSeekerObj.tagline = jobSeekerJSON.job_seeker_profile_tagline;
58
        jobSeekerObj.twitter_username = jobSeekerJSON.job_seeker_profile_twitter_link;
59
        jobSeekerObj.linkedin_username = jobSeekerJSON.job_seeker_profile_linkedin_link;
60
        jobSeekerObj.last_updated = jobSeekerJSON.last_updated;
61
        jobSeekerObj.user_id = jobSeekerJSON.user_id;
62
63
        var answers = [];
64
        for (var i = 0; i < jobSeekerJSON.job_seeker_profile_answers.length; i++) {
65
            var jsonAnswer = jobSeekerJSON.job_seeker_profile_answers[i];
66
            var answer = new JobSeekerAPI.JobSeekerProfileAnswer(jsonAnswer.job_seeker_profile_question_id, jsonAnswer.answer);
67
            answers.push(answer);
68
        }
69
        jobSeekerObj.answers = answers;
70
    } else {
71
        //TODO: make more robust
72
        //jobSeekerJSON could not be parsed, probably because profile doesnt exist yet
73
        //  Show default values.
74
        jobSeekerObj.id = 0;
75
        jobSeekerObj.name = "";
76
        jobSeekerObj.email = "";
77
        jobSeekerObj.personal_link = "";
78
        jobSeekerObj.tagline = "";
79
        jobSeekerObj.twitter_username = "";
80
        jobSeekerObj.linkedin_username = "";
81
        jobSeekerObj.answers = [];
82
        jobSeekerObj.last_updated = "";
83
    }
84
85
    Utilities.debug ? console.log(jobSeekerObj) : null;
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
86
87
    return jobSeekerObj;
88
};
89
90
JobSeekerAPI.refreshJobSeekerProfilePic = function () {
91
    if (UserAPI.hasSessionUser()) {
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
92
        var user_id = UserAPI.getSessionUserAsJSON()["user_id"];
0 ignored issues
show
Coding Style introduced by
['user_id'] could be written in dot notation.

You can rewrite this statement in dot notation:

var obj = { };
obj['foo'] = 'bar'; // Bad
obj.foo = 'bar'; // Good
Loading history...
93
        //profile_pic_elements = [document.getElementById("myProfilePic"), document.getElementById("profileBasicInfoEditProfilePic")];
94
        profile_pic_elements = [document.getElementById("myProfilePic")];
0 ignored issues
show
Bug introduced by
The variable profile_pic_elements seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.profile_pic_elements.
Loading history...
95
        ProfilePicAPI.refreshMultipleProfilePicsBackground(user_id, profile_pic_elements);
0 ignored issues
show
Bug introduced by
The variable ProfilePicAPI seems to be never declared. If this is a global, consider adding a /** global: ProfilePicAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
96
    }
97
};
98
99
JobSeekerAPI.populateJobSeekerProfile = function (jobSeekerProfile) {
100
101
    var profile_name = document.getElementById("updateProfileApplicantProfileFormNameLabelSpan");
102
    profile_name.innerHTML = jobSeekerProfile.name;
103
104
    var profile_id = document.getElementById("profileId");
105
    profile_id.value = jobSeekerProfile.id;
106
107
    var last_updated = document.getElementById("profileLastUpdated");
108
    last_updated.value = jobSeekerProfile.last_updated;
109
110
    var profile_tagline = document.getElementById("updateProfileApplicantProfileFormTaglineLabelSpan");
111
    profile_tagline.innerHTML = jobSeekerProfile.tagline;
112
113
    var twitter_name = document.getElementById("applicantProfileTwitterUsername");
114
    var twitter_link = document.getElementById("profileTwitterLink");
115
    var twitter_link_wrapper = document.getElementById("profileTwitterLinkWrapper");
116
    if (jobSeekerProfile.twitter_username == null || jobSeekerProfile.twitter_username == "") {
0 ignored issues
show
Best Practice introduced by
Comparing jobSeekerProfile.twitter_username to null using the == operator is not safe. Consider using === instead.
Loading history...
Coding Style introduced by
It is recommended to use === to compare with null.

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
Coding Style introduced by
It is recommended to use === to compare with .

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
117
        twitter_link_wrapper.classList.add("hidden");
118
        twitter_link.href = "#";
119
        twitter_name.value = "";
120
    } else {
121
        twitter_link_wrapper.classList.remove("hidden");
122
        twitter_link.href = JobSeekerAPI.twitterUsernameToLink(jobSeekerProfile.twitter_username);
123
        twitter_name.value = jobSeekerProfile.twitter_username;
124
    }
125
126
    var linkedin_name = document.getElementById("profileLinkedInUsername");
127
    var linkedin_link = document.getElementById("profileLinkedinLink");
128
    var linkedin_link_wrapper = document.getElementById("profileLinkedinLinkWrapper");
129
    if (jobSeekerProfile.linkedin_username == null || jobSeekerProfile.linkedin_username == "") {
0 ignored issues
show
Best Practice introduced by
Comparing jobSeekerProfile.linkedin_username to null using the == operator is not safe. Consider using === instead.
Loading history...
Coding Style introduced by
It is recommended to use === to compare with null.

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
Coding Style introduced by
It is recommended to use === to compare with .

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
130
        linkedin_link_wrapper.classList.add("hidden");
131
        linkedin_link.href = "";
132
        linkedin_name.value = "";
133
    } else {
134
        linkedin_link_wrapper.classList.remove("hidden");
135
        linkedin_link.href = unescape("https://www.linkedin.com/in/" + jobSeekerProfile.linkedin_username);
136
        linkedin_name.value = jobSeekerProfile.linkedin_username;
137
    }
138
139
    //Populate answer fields
140
    var job_seeker_profile_answers = jobSeekerProfile.answers;
141
    for (var i = 0; i < job_seeker_profile_answers.length; i++) {
142
        if (job_seeker_profile_answers[i] !== undefined) {
143
            var questionId = job_seeker_profile_answers[i].job_seeker_profile_question_id;
144
            var selector = ".profile-question__answer[data-question-id=\"" + questionId + "\"]";
145
            var answerField = document.querySelector(selector);
146
            if (answerField) {
147
                answerField.innerHTML = job_seeker_profile_answers[i].answer;
148
            }
149
        }
150
    }
151
};
152
153
JobSeekerAPI.resetProfileEditValues = function () {
154
    if (UserAPI.hasSessionUser()) {
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
155
        var sessionUser = UserAPI.getSessionUserAsJSON();
156
157
        var profile_edit_name = document.getElementById("profileEditName");
158
        profile_edit_name.value = sessionUser.name;
159
    }
160
    var profile_edit_tagline = document.getElementById("profileEditTagline");
161
    profile_edit_tagline.value = document.getElementById("updateProfileApplicantProfileFormTaglineLabelSpan").innerHTML;
162
163
    var profile_edit_twitter = document.getElementById("profileEditTwitter");
164
    profile_edit_twitter.value = document.getElementById("applicantProfileTwitterUsername").value;
165
166
    var profile_edit_linkedin = document.getElementById("profileEditLinkedin");
167
    profile_edit_linkedin.value = document.getElementById("profileLinkedInUsername").value;
168
};
169
170
JobSeekerAPI.twitterLinkToUsername = function (twitterLink) {
171
    if (twitterLink.startsWith("https://twitter.com/")) {
172
        return '@' + twitterLink.substring(20);
173
    } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
174
        return twitterLink;
175
    }
176
};
177
178
JobSeekerAPI.twitterUsernameToLink = function (twitterUsername) {
179
    if (twitterUsername.indexOf('@') == 0) {
0 ignored issues
show
Best Practice introduced by
Comparing twitterUsername.indexOf("'@'") to 0 using the == operator is not safe. Consider using === instead.
Loading history...
Coding Style introduced by
It is recommended to use === to compare with 0.

Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.

Read more about comparison operations.

Loading history...
180
        return "https://twitter.com/" + twitterUsername.substring(1);
181
    } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
182
        return twitterUsername;
183
    }
184
};
185
186
JobSeekerAPI.saveJobSeekerProfileChanges = function () {
187
    var jobSeekerBasicInfoForm = document.getElementById("profileBasicInfoForm");
188
189
    var jobSeekerProfile = new JobSeekerAPI.JobSeeker();
190
    var user = null;
0 ignored issues
show
Unused Code introduced by
The variable user seems to be never used. Consider removing it.
Loading history...
191
    if (UserAPI.hasSessionUser()) {
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
192
        user = UserAPI.getSessionUserAsJSON();
193
    } else {
194
        user = UserAPI.User();
195
    }
196
197
    /*user.firstname = jobSeekerBasicInfoForm.elements.profileEditFirstName.value;
198
     user.lastname = jobSeekerBasicInfoForm.elements.profileEditLastName.value;*/
199
200
    jobSeekerProfile.id = document.getElementById("profileId").value;
201
202
    jobSeekerProfile.last_updated = document.getElementById("profileLastUpdated").value;
203
204
    jobSeekerProfile.tagline = document.getElementById("profileEditTagline").value;
205
206
    jobSeekerProfile.twitter_username = jobSeekerBasicInfoForm.elements.profileEditTwitter.value;
207
208
    jobSeekerProfile.linkedin_username = escape(jobSeekerBasicInfoForm.elements.profileEditLinkedin.value);
209
210
    //Get answer values
211
    var answers = [];
212
    var answerFields = document.querySelectorAll(".profile-question__answer");
213
214
    for (var i = 0; i < answerFields.length; i++) {
215
        var questionId = answerFields[i].getAttribute("data-question-id");
216
        var answerText = answerFields[i].innerHTML;
217
        if (questionId) {
218
            answers.push(new JobSeekerAPI.JobSeekerProfileAnswer(questionId, answerText));
219
        }
220
    }
221
    jobSeekerProfile.answers = answers;
222
223
    jobSeekerProfile.personal_link = "";
224
    jobSeekerProfile.last_updated = "";
225
226
    //function(firstName, lastName, tagline, twitter, linkedin) {
227
    if (FormValidationAPI.validateUpdateProfileBasicInfo(
0 ignored issues
show
Bug introduced by
The variable FormValidationAPI seems to be never declared. If this is a global, consider adding a /** global: FormValidationAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
228
            //user.firstname, user.lastname,
229
            jobSeekerProfile.twitter_username, jobSeekerProfile.linkedin_username)) {
230
        //Also trigger photo upload
231
        if (JobSeekerAPI.profilePicUploader) {
232
            JobSeekerAPI.profilePicUploader.uploadPhoto();
233
        }
234
235
        //change twitter username to link
236
        //jobSeekerProfile.twitter_username = JobSeekerAPI.twitterUsernameToLink(jobSeekerProfile.twitter_username);
237
238
        JobSeekerAPI.saveJobSeekerProfile(jobSeekerProfile);
239
    }
240
};
241
242
243
/**
244
 *
245
 * @param {type} contactId
246
 * @returns {undefined}
247
 */
248
JobSeekerAPI.saveJobSeekerProfile = function (jobSeekerProfile) {
249
    var user = UserAPI.getSessionUserAsJSON();
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
250
    var saveJobSeekerProfile_url = DataAPI.baseURL + "/putJobSeekerProfileByUser/" + user.user_id;
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
251
    var jsonData = JSON.stringify(jobSeekerProfile);
252
    DataAPI.sendRequest(saveJobSeekerProfile_url, 'PUT', {}, jsonData, function(request){
253
        JobSeekerAPI.hideJobSeekerProfileEditOverlays();
254
        JobSeekerAPI.saveJobSeekerProfileLoaded(request.response);
255
    });
256
};
257
258
JobSeekerAPI.saveJobSeekerProfileLoaded = function (response) {
259
    Utilities.debug ? console.log(response) : null;
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
Did you forget to assign or call a function?

This error message can for example pop up if you forget to assign the result of a function call to a variable or pass it to another function:

function someFunction(x) {
    (x > 0) ? callFoo() : callBar();
}

// JSHint expects you to assign the result to a variable:
function someFunction(x) {
    var rs = (x > 0) ? callFoo() : callBar();
}

// If you do not use the result, you could also use if statements in the
// case above.
function someFunction(x) {
    if (x > 0) {
        callFoo();
    } else {
        callBar();
    }
}
Loading history...
260
    DataAPI.getJobSeekerProfileByUserId(UserAPI.getSessionUserAsJSON().user_id, function (response) {
0 ignored issues
show
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
261
        var jobSeekerProfile = JobSeekerAPI.populateJobSeekerObject(JSON.parse(response));
262
        JobSeekerAPI.resetProfileEditValues();
263
        JobSeekerAPI.populateJobSeekerProfile(jobSeekerProfile);
264
    });
265
};
266
267
JobSeekerAPI.showMyJobSeekerProfile = function () {
268
    var stateInfo = {pageInfo: 'my_profile', pageTitle: 'Talent Cloud: My Profile'};
269
    document.title = stateInfo.pageTitle;
270
    history.pushState(stateInfo, stateInfo.pageInfo, '#MyProfile');//last parameter just replaced with #MyProfile instead of url
0 ignored issues
show
Bug introduced by
The variable history seems to be never declared. If this is a global, consider adding a /** global: history */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
271
272
    TalentCloudAPI.hideAllContent();
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
273
    //TalentCloudAPI.hideLogo();
274
275
    var jobSeekerProfileOverlay = document.getElementById("profileSection");
276
    jobSeekerProfileOverlay.classList.remove("hidden");
277
278
    var profileBasicInfoEdit = document.getElementById("profileBasicInfoEditWrapper");
279
    profileBasicInfoEdit.classList.remove("hidden");
280
281
    LookupAPI.getLookupResponse("job_seeker_profile_question", function (questionLookupMap) {
0 ignored issues
show
Bug introduced by
The variable LookupAPI seems to be never declared. If this is a global, consider adding a /** global: LookupAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
282
        JobSeekerAPI.addProfileQuestionSections(questionLookupMap, true);
283
        
284
        //Questions must be loaded before profile, with answers, can be populated
285
        DataAPI.getJobSeekerProfileByUserId(UserAPI.getSessionUserAsJSON().user_id, function (response) {
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable DataAPI seems to be never declared. If this is a global, consider adding a /** global: DataAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
286
            var jobSeekerProfile = JobSeekerAPI.populateJobSeekerObject(JSON.parse(response));
287
            JobSeekerAPI.populateJobSeekerProfile(jobSeekerProfile);
288
        });
289
    });
290
291
    EventsAPI.hideBodyOverflow(false);
0 ignored issues
show
Bug introduced by
The variable EventsAPI seems to be never declared. If this is a global, consider adding a /** global: EventsAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
292
    //AccessibilityAPI.preventModalEscapeBackward("jobSeekerCloseButton");
293
    //AccessibilityAPI.preventModalEscapeForward("goToAccomplishmentsButton");
294
295
296
    AccessibilityAPI.addEscapeListener("JobSeekerAPI.hideJobSeekerProfileEditOverlays", null);
0 ignored issues
show
Bug introduced by
The variable AccessibilityAPI seems to be never declared. If this is a global, consider adding a /** global: AccessibilityAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
297
    JobSeekerAPI.refreshJobSeekerProfilePic();
298
299
    // New Subpage Hero Scripts
300
301
    Utilities.getHeroElements();
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
302
303
    var profileHeroTitle = document.getElementById("profileHeroTitle");
304
    profileHeroTitle.classList.remove("hidden");
305
    profileHeroTitle.setAttribute("aria-hidden", "false");
306
307
    // Mobile Menu Overflow Release
308
    document.body.style.overflowY = "auto";
309
310
    // Google Analytics
311
312
    ga('set', 'page', '/my-profile');
313
    ga('send', 'pageview');
314
};
315
316
JobSeekerAPI.showJobSeekerProfileForApplication = function (jobSeekerProfile, applicationId) {
317
    var stateInfo = {pageInfo: 'view_application_profile', pageTitle: 'Talent Cloud: Applicant Profile'};
318
    document.title = stateInfo.pageTitle;
319
    history.pushState(stateInfo, stateInfo.pageInfo, '#ViewApplicationProfile/' + applicationId);
0 ignored issues
show
Bug introduced by
The variable history seems to be never declared. If this is a global, consider adding a /** global: history */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
320
321
    TalentCloudAPI.hideAllContent();
0 ignored issues
show
Bug introduced by
The variable TalentCloudAPI seems to be never declared. If this is a global, consider adding a /** global: TalentCloudAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
322
    //TalentCloudAPI.hideLogo();
323
324
    var jobSeekerProfileOverlay = document.getElementById("profileSection");
325
    jobSeekerProfileOverlay.classList.remove("hidden");
326
327
    var profileBasicInfoEdit = document.getElementById("profileBasicInfoEditWrapper");
328
    profileBasicInfoEdit.classList.add("hidden");
329
330
    LookupAPI.getLookupResponse("job_seeker_profile_question", function (questionLookupMap) {
0 ignored issues
show
Bug introduced by
The variable LookupAPI seems to be never declared. If this is a global, consider adding a /** global: LookupAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
331
        JobSeekerAPI.addProfileQuestionSections(questionLookupMap, false);
332
        
333
        //Questions must be loaded before profile, with answers, can be populated
334
        JobSeekerAPI.populateJobSeekerProfile(jobSeekerProfile);
335
    });
336
337
    EventsAPI.hideBodyOverflow(false);
0 ignored issues
show
Bug introduced by
The variable EventsAPI seems to be never declared. If this is a global, consider adding a /** global: EventsAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
338
    //AccessibilityAPI.preventModalEscapeBackward("jobSeekerCloseButton");
339
    //AccessibilityAPI.preventModalEscapeForward("goToAccomplishmentsButton");
340
341
    AccessibilityAPI.addEscapeListener("JobSeekerAPI.hideJobSeekerProfileEditOverlays", null);
0 ignored issues
show
Bug introduced by
The variable AccessibilityAPI seems to be never declared. If this is a global, consider adding a /** global: AccessibilityAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
342
    ProfilePicAPI.refreshProfilePicBackground(jobSeekerProfile.user_id, document.getElementById("myProfilePic"));
0 ignored issues
show
Bug introduced by
The variable ProfilePicAPI seems to be never declared. If this is a global, consider adding a /** global: ProfilePicAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
343
344
    // New Subpage Hero Scripts
345
346
    Utilities.getHeroElements();
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
347
348
    var profileHeroTitle = document.getElementById("profileHeroTitle");
349
    profileHeroTitle.classList.remove("hidden");
350
    profileHeroTitle.setAttribute("aria-hidden", "false");
351
352
    // Mobile Menu Overflow Release
353
    document.body.style.overflowY = "auto";
354
355
    // Google Analytics
356
357
    //TODO: ensure GA calls are correct
358
    ga('set', 'page', '/profile-for-application/' + applicationId);
359
    ga('send', 'pageview');
360
};
361
362
/**
363
 *
364
 * @param {type} questionLookupMap - array of objects with .id, .description, .value properties
365
 * @return {undefined}
366
 */
367
JobSeekerAPI.addProfileQuestionSections = function (questionLookupMap, isEditable) {
368
    //Create and populate Profile Question field elements
369
    var questionFragment = document.createDocumentFragment();
370
371
372
    for (var i = 0; i < questionLookupMap.length; i++) {
373
        var question = questionLookupMap[i];
374
375
        var questionSection = JobSeekerAPI.createQuestionSectionElement(question, isEditable);
376
377
        //Add to the wrapper fragment
378
        questionFragment.appendChild(questionSection);
379
    }
380
381
    var questionWrapper = document.getElementById("profileQuestionsWrapper");
382
    //Clear previous values to avoid doubles
383
    questionWrapper.innerHTML = "";
384
385
    //Add questions to wrapper
386
    questionWrapper.appendChild(questionFragment);
387
};
388
389
390
JobSeekerAPI.createQuestionSectionElement = function (question, isEditable) {
391
    var questionSection = document.createElement("div");
392
    questionSection.classList.add("applicant-profile__question");
393
394
    var questionTitleBar = document.createElement("h4");
395
    questionTitleBar.classList.add("applicant-profile__question-title-wrapper");
396
397
    var questionTitle = document.createElement("span");
398
    questionTitle.innerHTML = question.value;
399
400
    var questionAnswer = document.createElement("p");
401
    questionAnswer.classList.add("profile-question__answer");
402
    questionAnswer.setAttribute("data-question-id", question.id);
403
404
    //Now put it all together, from the inside out
405
    questionTitleBar.appendChild(questionTitle);
406
407
    questionSection.appendChild(questionTitleBar);
408
    questionSection.appendChild(questionAnswer);
409
410
    if (isEditable === true) {
411
        var questionEditBtn = document.createElement("a");
412
        questionEditBtn.classList.add("applicant-profile__edit-trigger");
413
        questionEditBtn.setAttribute("role", "button");
414
        questionEditBtn.href = "javascript:void(0)";
0 ignored issues
show
Coding Style introduced by
Script urls should not be used.
Loading history...
415
        questionEditBtn.setAttribute("title", 'Edit "' + question.value + '"');
416
417
        var questionEditBtnScreenReaderText = document.createElement("span");
418
        questionEditBtnScreenReaderText.classList.add("hidden");
419
        questionEditBtnScreenReaderText.innerHTML = 'Edit "'+question.value+'"';
420
421
        questionEditBtn.appendChild(questionEditBtnScreenReaderText);
422
423
        questionEditBtn.setAttribute("data-question-id", question.id);
424
        questionEditBtn.setAttribute("data-question-value", question.value);
425
        questionEditBtn.setAttribute("data-question-description", question.description);
426
427
        questionEditBtn.onclick = function () {
428
            var id = this.getAttribute("data-question-id");
429
            var value = this.getAttribute("data-question-value");
430
            var description = this.getAttribute("data-question-description");
431
            JobSeekerAPI.showEditProfileAnswerModal(id, value, description);
432
        };
433
434
        var questionEditBtnImage = document.createElement("i");
435
        questionEditBtnImage.classList.add("fa");
436
        questionEditBtnImage.classList.add("fa-pencil-square");
437
438
        //Append edit button
439
        questionEditBtn.appendChild(questionEditBtnImage);
440
        questionTitleBar.appendChild(questionEditBtn);
441
    }
442
443
    return questionSection;
444
};
445
446
JobSeekerAPI.showEditProfileAnswerModal = function (questionId, questionName, questionDescription) {
447
    if (siteContent) {
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable siteContent is declared in the current environment, consider using typeof siteContent === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
448
        var title = siteContent.editYour + " \"" + questionName + "\"";
449
    } else {
450
        var title = "Edit your \"" + questionName + "\"";
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable title already seems to be declared on line 448. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
Bug introduced by
It seems like title was already defined.
Loading history...
451
    }
452
453
454
    document.getElementById("profileEditAnswerTitle").title = title;
0 ignored issues
show
Bug introduced by
The variable title seems to be used out of scope.

This error can usually be fixed by declaring the variable in the scope where it is used:

function someFunction() {
    (function() {
        var i = 0;
    })();

    // i is not defined.
    alert(i);
}

// This can be fixed by moving the var statement to the outer scope.

function someFunction() {
    var i;
    (function() {
        i = 1;
    })();

    alert(i);
};
Loading history...
455
    document.getElementById("profileEditAnswerTitle").innerHTML = title;
0 ignored issues
show
Bug introduced by
The variable title seems to be used out of scope.

This error can usually be fixed by declaring the variable in the scope where it is used:

function someFunction() {
    (function() {
        var i = 0;
    })();

    // i is not defined.
    alert(i);
}

// This can be fixed by moving the var statement to the outer scope.

function someFunction() {
    var i;
    (function() {
        i = 1;
    })();

    alert(i);
};
Loading history...
456
    document.getElementById("profileEditAnswerFormDescription").innerHTML = title;
0 ignored issues
show
Bug introduced by
The variable title seems to be used out of scope.

This error can usually be fixed by declaring the variable in the scope where it is used:

function someFunction() {
    (function() {
        var i = 0;
    })();

    // i is not defined.
    alert(i);
}

// This can be fixed by moving the var statement to the outer scope.

function someFunction() {
    var i;
    (function() {
        i = 1;
    })();

    alert(i);
};
Loading history...
457
    document.getElementById("profile-edit-answer__question-id").value = questionId;
458
    document.getElementById("profileEditAnswerLabel").innerHTML = questionName;
459
    document.getElementById("dialogueModalSupportCopy").innerHTML = questionDescription;
460
461
    var answerField = document.querySelector('.profile-question__answer[data-question-id="' + questionId + '"]');
462
    if (answerField && answerField.innerHTML) {
463
        //If answer text already exists, prepopulate edit text box
464
        document.getElementById("profileEditAnswer").value = answerField.innerHTML;
465
    } else {
466
        //Else, reset text so placeholder shows
467
        document.getElementById("profileEditAnswer").value = "";
468
    }
469
470
    //Unhide modal
471
    var jobSeekerAboutMeEditOverlay = document.getElementById("profileEditAnswerOverlay");
472
    jobSeekerAboutMeEditOverlay.classList.remove("hidden");
473
474
    AccessibilityAPI.preventModalEscape("profileEditAnswer", "profileEditAnswerSave");
0 ignored issues
show
Bug introduced by
The variable AccessibilityAPI seems to be never declared. If this is a global, consider adding a /** global: AccessibilityAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
475
    AccessibilityAPI.focusElement("profileEditAnswer");
476
477
    EventsAPI.hideBodyOverflow(true);
0 ignored issues
show
Bug introduced by
The variable EventsAPI seems to be never declared. If this is a global, consider adding a /** global: EventsAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
478
479
    modalSize();
480
};
481
482
JobSeekerAPI.saveJobSeekerProfileAnswer = function () {
483
    var questionId = document.getElementById("profile-edit-answer__question-id").value;
484
    if (questionId) {
485
        var answerField = document.querySelector('.profile-question__answer[data-question-id="' + questionId + '"]');
486
        var answerText = document.getElementById("profileEditAnswer");
487
        if (answerField && answerText) {
488
            Utilities.replaceElementText(answerField, answerText.value);
0 ignored issues
show
Bug introduced by
The variable Utilities seems to be never declared. If this is a global, consider adding a /** global: Utilities */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
489
            JobSeekerAPI.saveJobSeekerProfileChanges();
490
        }
491
    }
492
    JobSeekerAPI.hideJobSeekerProfileEditAnswerModal();
493
}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
494
495
JobSeekerAPI.hideJobSeekerProfileForm = function () {
496
    var jobSeekerProfileOverlay = document.getElementById("profileSection");
497
    jobSeekerProfileOverlay.classList.add("hidden");
498
499
    //EventsAPI.hideBodyOverflow(false);
500
501
    //FormsAPI.steppedForm.validateStep('contact_details','jobSeekerFormStepGroup',false,null,null);
502
};
503
504
JobSeekerAPI.showJobSeekerProfileBasicInfoEdit = function () {
505
    //TODO: push state info to history
506
507
    var jobSeekerBasicInfoEditOverlay = document.getElementById("profileBasicInfoEditOverlay");
508
    jobSeekerBasicInfoEditOverlay.classList.remove("hidden");
509
510
    AccessibilityAPI.preventModalEscape("updateProfileChoosePhotoButtonLabel", "profileBasicInfoEditSave");
0 ignored issues
show
Bug introduced by
The variable AccessibilityAPI seems to be never declared. If this is a global, consider adding a /** global: AccessibilityAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
511
    AccessibilityAPI.focusElement("updateProfileChoosePhotoButtonLabel");
512
513
    EventsAPI.hideBodyOverflow(true);
0 ignored issues
show
Bug introduced by
The variable EventsAPI seems to be never declared. If this is a global, consider adding a /** global: EventsAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
514
515
    var fileInputButtons = [document.getElementById('updateProfileChoosePhotoButton'),
516
        document.getElementById('updateProfileChooseAltPhotoButton')];
517
    var fileDrop = document.getElementById('updateProfilePhotoDraggableArea');
518
    var imagePreview = document.getElementById('updateProfilePhotoCroppieContainer');
519
    var clearBtn = document.getElementById('updateProfilePhotoCancelButton');
520
    //var uploadBtn = document.getElementById('profilePicUploadBtn');
521
522
    //Don't pass in a save button, because there is no dedicated button for pic uploading.
523
    //The save button must upload photo, as well as profile info.
524
    JobSeekerAPI.profilePicUploader = new ProfilePicAPI.Uploader(
0 ignored issues
show
Bug introduced by
The variable ProfilePicAPI seems to be never declared. If this is a global, consider adding a /** global: ProfilePicAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
525
            fileInputButtons,
526
            fileDrop,
527
            imagePreview,
528
            clearBtn,
529
            null,
530
            UserAPI.getSessionUserAsJSON().user_id,
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
531
            JobSeekerAPI.onProfilePicUploaded
532
            );
533
534
    modalSize();
535
536
};
537
538
JobSeekerAPI.hideJobSeekerProfileBasicInfoEdit = function () {
539
    //TODO modify state info history ?
540
    var jobSeekerBasicInfoEditOverlay = document.getElementById("profileBasicInfoEditOverlay");
541
    jobSeekerBasicInfoEditOverlay.classList.add("hidden");
542
543
    JobSeekerAPI.resetProfileEditValues();
544
545
    EventsAPI.hideBodyOverflow(false);
0 ignored issues
show
Bug introduced by
The variable EventsAPI seems to be never declared. If this is a global, consider adding a /** global: EventsAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
546
};
547
548
JobSeekerAPI.hideJobSeekerProfileEditAnswerModal = function () {
549
    var jobSeekerEditAnswerOverlay = document.getElementById("profileEditAnswerOverlay");
550
    jobSeekerEditAnswerOverlay.classList.add("hidden");
551
552
    JobSeekerAPI.resetProfileEditValues();
553
554
    EventsAPI.hideBodyOverflow(false);
0 ignored issues
show
Bug introduced by
The variable EventsAPI seems to be never declared. If this is a global, consider adding a /** global: EventsAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
555
};
556
557
JobSeekerAPI.hideJobSeekerProfileEditOverlays = function () {
558
    var jobSeekerBasicInfoEditOverlay = document.getElementById("profileBasicInfoEditOverlay");
559
    jobSeekerBasicInfoEditOverlay.classList.add("hidden");
560
561
    var jobSeekerEditAnswerOverlay = document.getElementById("profileEditAnswerOverlay");
562
    jobSeekerEditAnswerOverlay.classList.add("hidden");
563
564
    JobSeekerAPI.resetProfileEditValues();
565
566
    EventsAPI.hideBodyOverflow(false);
0 ignored issues
show
Bug introduced by
The variable EventsAPI seems to be never declared. If this is a global, consider adding a /** global: EventsAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
567
}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
568
569
JobSeekerAPI.showUploadProfilePic = function () {
570
    //TODO: enable slide transition between divs
571
572
    var profileBasicInfoFormWrapper = document.getElementById("profileBasicInfoFormWrapper");
573
    profileBasicInfoFormWrapper.classList.add("hidden");
574
575
    var profilePicUploadWrapper = document.getElementById("profilePicUploadWrapper")
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
576
    profilePicUploadWrapper.classList.remove("hidden");
577
578
    // AccessibilityAPI.preventModalEscape("profilePicUploadField", "profilePicUploadBtn");
579
    // AccessibilityAPI.focusElement("profilePicUploadField");
580
581
    var fileInputButtons = [document.getElementById('updateProfileChoosePhotoButton'),
582
        document.getElementById('updateProfileChooseAltPhotoButton')];
583
    var fileDrop = document.getElementById('updateProfilePhotoDraggableArea');
584
    var imagePreview = document.getElementById('updateProfilePhotoCroppieContainer');
585
    var clearBtn = document.getElementById('updateProfilePhotoCancelButton');
586
    //var uploadBtn = document.getElementById('profilePicUploadBtn');
587
588
    JobSeekerAPI.profilePicUploader = new ProfilePicAPI.Uploader(
0 ignored issues
show
Bug introduced by
The variable ProfilePicAPI seems to be never declared. If this is a global, consider adding a /** global: ProfilePicAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
589
            fileInputButtons,
590
            fileDrop,
591
            imagePreview,
592
            clearBtn,
593
            null,
594
            UserAPI.getSessionUserAsJSON().user_id,
0 ignored issues
show
Bug introduced by
The variable UserAPI seems to be never declared. If this is a global, consider adding a /** global: UserAPI */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
595
            JobSeekerAPI.onProfilePicUploaded
596
            );
597
598
};
599
600
JobSeekerAPI.onProfilePicUploaded = function () {
601
    JobSeekerAPI.refreshJobSeekerProfilePic();
602
};
603